<%--
  Created by IntelliJ IDEA.
  User: Cc
  Date: 2020/12/30
  Time: 16:51
  To change this template use File | Settings | File Templates.
--%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fml" uri="http://java.sun.com/jstl/fmt_rt" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="<%=basePath%>static/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="<%=basePath%>static/css/font.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/xadmin.css">
    <script type="text/javascript" src="<%=basePath%>static/js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/xadmin.js"></script>
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>用户名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="username" name="username" readonly
                       autocomplete="off" class="layui-input" value="${user.username}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="password" class="layui-form-label">
                密&emsp;码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="password" name="password" lay-affix="eye"
                       autocomplete="off" class="layui-input" value="${user.password}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                电&emsp;话
            </label>
            <div class="layui-input-inline">
                <input type="tel" id="phone" name="phone"
                       autocomplete="off" class="layui-input" value="${user.phone}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="email" class="layui-form-label">
                邮&emsp;箱
            </label>
            <div class="layui-input-inline">
                <input type="email" id="email" name="email"
                       autocomplete="off" class="layui-input" value="${user.email}">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="birthday" class="layui-form-label">生日</label>
                <div class="layui-input-inline">
                    <input type="date" class="layui-input" id="birthday" placeholder="yyyy-MM-dd"
                        value="<fml:formatDate value="${user.birthday}" pattern="yyyy-MM-dd"></fml:formatDate>">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" id="L_repass" type="button">
                修改
            </button>
        </div>
    </form>
</div>
</body>
<script type="text/javascript">
    $(document).on('click', '#L_repass', function() {
        submit();
    });
    function submit(){
        let user = {
            username: $("#username").val(),
            password: $("#password").val(),
            phone: $("#phone").val(),
            email: $("#email").val(),
            birthday: $("#birthday").val(),
        };
        // console.log(user);
        $.ajax({
            url: "/user/editUser",
            type: "post",
            datatype: "json",
            contentType: "application/json",
            data: JSON.stringify(user),
            success: function (data){
                // console.log(data);
                parent.layer.close(layer.index);//关闭弹出层
                layer.msg(data.message, {icon: 1});
                setTimeout(function(){
                    window.parent.location.reload();//刷新父页面
                }, 1000);
                // data.code === 200 ? location.href = data.url : location.reload();
            },
            error: function (data){
                alert("修改失败！");
            }
        })
    }
</script>
</html>